package com.example.demo.controller;

import com.example.demo.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author Jamie.王
 * @description
 * @date 2021/11/18 11:17
 */
@RestController
@RequestMapping("excel")
@Slf4j
public class ExcelController {

    @Autowired
    private ExcelService excelService;

    @PostMapping("/importAndParse")
    public String importLogisticsCcode(@RequestParam("fileName") MultipartFile file) {
        try {
            return excelService.importAndParse(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "系统异常,导入不成功";
    }

    @GetMapping(value ="/downResultData",produces = "text/html;charset=UTF-8")
    public void downResultData(@RequestParam String monthDate, HttpServletResponse response, HttpServletRequest request){
        try {
            excelService.downResultData(monthDate,response,request);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}